<?php
class LoginLog extends BaseActiveRecord
{
    
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return '{{login_log}}';
    }

    public function add($arr)
    {
        $result = array();
        if(empty($arr['sid'])) {
            $result['errno'] = 4354;
            $result['errmsg'] = '请传用户id';
            return $result;
        }

        $log = new LoginLog;
        if(!empty($arr['sid'])){
            $log->sid = $arr['sid'];
        }

        if(!empty($arr['ip'])){
            $log->ip = $arr['ip'];
        }
        if(!empty($arr['check_method'])){
            $log->check_method = $arr['check_method'];
        }
        if(!empty($arr['client_id'])){
            $log->client_id = $arr['client_id'];
        }
        $status = $log->save();
        if($status){
            $result['errno'] = 0 ;
            $result['errmsg'] = 'success';
            return $result;
        }else{
            $result['errno'] = 543;
            $result['errmsg'] = '保存失败';
            return $result; 
        }

    }

    public function behaviors()
    {
        return array(
            'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
                'createAttribute' => 'ctime',
                'updateAttribute' => 'mtime',
                'setUpdateOnCreate'=> true,
            ),
        );
    }

}

?>